import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import datetime

def getDriver(proxyIP):
    print("proxyIP:",proxyIP)
    driver = webdriver.PhantomJS()
    headers = {
        'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0',
        'Accept' : 'application/json, text/plain, */*',
        'Accept-Language' : 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
        'Connection' : 'keep-alive',
        }
    desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
    proxy = webdriver.Proxy()
    proxy.proxy_type = ProxyType.MANUAL
    proxy.http_proxy = proxyIP
    proxy.add_to_capabilities(desired_capabilities)
    for key, value in headers.items():
        desired_capabilities['phantomjs.page.customHeaders.{}'.format(key)] = value
    driver.start_session(desired_capabilities)
    driver.implicitly_wait(5)#隐形等待,设置了一个最长等待时间，如果在规定时间内网页加载完成，则执行下一步，否则一直等到时间截止，抛出异常，然后执行下一步
    driver.set_page_load_timeout(50)
    return driver